package kr.ac.kaist.wheretoeat;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkConnectionChecker {
	 
    public static boolean IsWifiAvailable(Context context)
    {
        ConnectivityManager m_NetConnectMgr= (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        boolean bConnect = false;
        try
        {
            if( m_NetConnectMgr == null ) return false;
 
            NetworkInfo info = m_NetConnectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
            bConnect = (info.isAvailable() && info.isConnected());
 
        }
        catch(Exception e)
        {
            return false;
        }
 
        return bConnect;
    }
 
    public static boolean Is3GAvailable(Context context)
    {  
        ConnectivityManager m_NetConnectMgr= (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
        boolean bConnect = false;
        try
        {
            if( m_NetConnectMgr == null ) return false;
            NetworkInfo info = m_NetConnectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
            bConnect = (info.isAvailable() && info.isConnected());
        }
        catch(Exception e)
        {
            return false;
        }
 
        return bConnect;
    }
    
    public static boolean IsNetworkAvailable(Context context)
    {
    	if((false == Is3GAvailable(context)) && 
    		(false == IsWifiAvailable(context))){
    		//3G & WIFI are not available	
    	    return false;   		
    	}
    	else
    		return true;

    }
}